package com.atguigu.springcloud.controller;


import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.atguigu.springcloud.entity.CommonResult;
import com.atguigu.springcloud.entity.Payment;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
@Api("OrderController")
@RequestMapping(value = "/consumer")
public class OrderController {
	@Resource
	private RestTemplate restTemplate;
	private  final String pay_url = "http://cloud-privater-payment";
	
	@PostMapping(value = "/create")
	public CommonResult create(@RequestBody Payment payment) {
		log.info("插入：" +payment);
		return restTemplate.postForObject(pay_url+"/payment/create", payment, CommonResult.class);
	}

	@GetMapping(value = "/get/{id}")
	public CommonResult get(@PathVariable long id) {
		log.info("查询：" );
		return restTemplate.getForObject(pay_url+"/payment/get/"+id,  CommonResult.class);
	}
}
